/**
 * @param {string} expression
 * @return {boolean}
 */
var parseBoolExpr = function (expression) {
  let stack = []
  let op, top
 
  for (let i = 0; i < expression.length; i++) {
    if (expression[i] == ',') {
      continue
    } else if (expression[i] != ')') {
      stack.push(expression[i])
    } else {
      let tNum = 0,
      fNum = 0
      while (stack[stack.length-1] != '(') {

        top = stack.pop()
        if (top == 't') {
          tNum++
        } else {
          fNum++
        }
      }

      stack.pop()
      op = stack.pop()
      switch (op) {
        case '!':
          stack.push(fNum == 1 ? 't' : 'f')
          break
        case '&':
          stack.push(fNum == 0 ? 't' : 'f')
          break
        case '|':
          stack.push(tNum >0? 0 ? 't' : 'f')
        default:
          break
      }
    }
  }
  return stack.pop() === 't'
}
